﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace UCLib
{
    public class DicLoader
    {
        static private System.Windows.Forms.OpenFileDialog openFileDialog1=new OpenFileDialog();

        public static IList<string> GetFilesList()
        {
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = openFileDialog1.FileName;

                List<string> paramsList = GetParamsFromFile(path);

                return paramsList;
            }

            return null;
        }

        public static List<string> GetParamsFromFile(string path)
        {
            List<string> Lines = new List<string>();
            string strLine;
            try
            {
                FileStream aFile = new FileStream(path, FileMode.Open);
                StreamReader sr = new StreamReader(aFile);
                strLine = sr.ReadLine();
                Lines.Add(strLine);
                //Read data in line by line 
                while (strLine != null)
                {
                    strLine = sr.ReadLine();
                    if (string.IsNullOrEmpty(strLine)) continue;
                    if (string.IsNullOrEmpty(strLine.Trim())) continue;
                    Lines.Add(strLine);
                }

                sr.Close();

                return Lines;
            }
            catch (IOException ex)
            {
                return new List<string>();
            }
        }
    }
}
